package org.dong.Controller;

import com.alibaba.fastjson.JSON;
import org.dong.Dao.TranDaoImpl;
import org.dong.Model.DownloadList;
import org.dong.Pojo.Dto;
import org.dong.Pojo.HttpRequest;
import org.dong.Pojo.HttpResponse;
import org.dong.Tool.Data;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class GetDownListController implements ServerLet {

    @Override
    public void server(HttpRequest request, OutputStream os) {
        Dto dto = new Dto();
        String msg = "OK";

        Map<String,String> map = new HashMap<>();
        map.put("id",Data.user.getId()+"");
        ArrayList<DownloadList> list = new TranDaoImpl().getDownList(map);

        if(list.size() > 0 ){
            dto.setData(list);
            dto.setErrMsg("传输列表");
            dto.setStatusCode(2000);
        }else{
            dto.setStatusCode(20001);
            dto.setErrMsg("没有查找到数据");
        }

        msg = JSON.toJSONString(dto);

        new HttpResponse(os,request.getUrl(),msg);
    }
}
